
import Vue from "vue";
import $ from "jquery";

import {notificationA} from "../hos/notificationA.js";
import {Activity} from "./activity.js";


class NotificationTest extends Activity{

    onCreate() {
        super.onCreate();

        new Vue({
            el: this.find("enable"),
            methods: {
                click: ()=> {
                    notificationA.enable()
                        .then(()=>{alert("通知使用权打开成功");})
                        .catch((error)=>{alert(error.errMsg);});
                }
            }});

        $(this.find("log")).append("通知状态:" + notificationA.isEnabled() + "<br>");
    }

    onNotification(event) {
        // alert("收到通知")
        let data = event.data;
        $(this.find("log")).append("通知:" + JSON.stringify(data) + "<br>");
    }

    onResume() {
        super.onResume();
        // alert("添加通知")
        notificationA.addRecvObserver(this.onNotification, this);
    }

    onPause() {
        super.onPause();
        // alert("移除通知")
        notificationA.removeRecvObserver(this.onNotification);
    }

}

export {NotificationTest};
